package com.stlm2.dems.service;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;

import com.stlm2.dems.entity.IntegralGoods;
import com.stlm2.dems.dao.IntegralGoodsDao;
import com.stlm2.core.base.BaseDao;
import com.stlm2.core.base.impl.BaseServiceImpl;
import org.springframework.ui.ModelMap;

import java.util.ArrayList;
import java.util.List;

@Service("integralGoodsService")
@Transactional(rollbackForClassName={"java.lang.Exception"}, propagation = Propagation.REQUIRED)
public class IntegralGoodsService extends BaseServiceImpl<IntegralGoods> {

	@Resource
	private IntegralGoodsDao integralGoodsDao;

	@Override
	protected BaseDao <IntegralGoods> getDao() {
		return integralGoodsDao;
	}

    public List<ModelMap> convertModel(List<IntegralGoods> integralGoodsList) {
		List<ModelMap> list = new ArrayList<ModelMap>();
		if (integralGoodsList != null && integralGoodsList.size() > 0) {
			for (IntegralGoods integralGoods : integralGoodsList) {
				ModelMap map = buildModel(integralGoods);
				list.add(map);
			}
		}
		return list;
    }

	public ModelMap buildModel(IntegralGoods integralGoods) {
		ModelMap model = new ModelMap();
		model.put("id",integralGoods.getId());
		model.put("name",integralGoods.getName());
		model.put("abbreviation",integralGoods.getAbbreviation());
		model.put("state",integralGoods.getState()==1?"有效":"无效");
		model.put("mainImg",integralGoods.getMainImg());
		model.put("detailsImg",integralGoods.getDetailsImg());
		model.put("inventory",integralGoods.getInventory());
		model.put("unitIntegral",integralGoods.getUnitIntegral());
		model.put("totalIntegral",integralGoods.getTotalIntegral()!=null?integralGoods.getTotalIntegral():"");
		model.put("goodsType",integralGoods.getGoods_type().toString());
		model.put("goodsTypeValue",integralGoods.getGoods_type().getIntValue());
		model.put("stateValue",integralGoods.getState());
		return  model;
	}
}